package com.woniuxy.core.listener;

import com.rabbitmq.client.Channel;
import com.woniuxy.mq.message.LikeMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 饶志
 * @version 1.0
 * @since 2025-07-23  02:46
 */
@Component
@Slf4j
public class LikeDlqListener {

    @RabbitListener(queues = "like_dlq_queue")
    public void handleDlqMessage(LikeMessage message, Channel channel,
                                 @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
        log.error("死信队列接收到消息，需人工处理: {}", message);
        try {
            channel.basicAck(deliveryTag, false); // 确认死信消息（或根据业务需求处理）
        } catch (IOException e) {
            log.error("死信消息确认失败: {}", e.getMessage());
        }
    }
}
